package com.slipper.core.excel;

import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.data.WriteCellData;
import com.alibaba.excel.metadata.property.ExcelContentProperty;
import com.alibaba.excel.util.DateUtils;
import com.alibaba.excel.util.WorkBookUtil;

import java.time.LocalDateTime;

public class DateTimeDateConverter implements Converter<LocalDateTime> {
    public DateTimeDateConverter() {
    }

    public Class<?> supportJavaTypeKey() {
        return LocalDateTime.class;
    }

    public WriteCellData<?> convertToExcelData(
            LocalDateTime value,
            ExcelContentProperty contentProperty,
            GlobalConfiguration globalConfiguration) {
        WriteCellData<?> cellData = new WriteCellData<>(value);
        WorkBookUtil.fillDataFormat(cellData, "yyyy-MM-dd HH:mm:ss", DateUtils.defaultDateFormat);
        return cellData;
    }
}
